unit uListaDostawcow;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB, ADODB, GridsEh, DBGridEh, StdCtrls;

type
  TFListaDostawcow = class(TForm)
    Button2: TButton;
    Button1: TButton;
    GroupBox1: TGroupBox;
    DBGridEh1: TDBGridEh;
    qDostawcy: TADOQuery;
    dsDostawcy: TDataSource;
    edID: TEdit;
    edNazwa: TEdit;
    procedure clickFiltr(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    Dostawca: string;
  end;

var
  FListaDostawcow: TFListaDostawcow;

implementation

{$R *.dfm}

procedure TFListaDostawcow.Button1Click(Sender: TObject);
begin
  Close;
end;

procedure TFListaDostawcow.Button2Click(Sender: TObject);
begin
  if not qDostawcy.IsEmpty then   
    Dostawca := trim(qDostawcy.Fields[0].AsString);
  Close;  
end;

procedure TFListaDostawcow.clickFiltr(Sender: TObject);
var
  s : string;
begin
  qDostawcy.Filtered := False;
  s := '';
  if trim(edID.Text)<>'' then begin
    s := 'VENDORID like ''%'+edID.Text+'%'' ';
    if trim(edNazwa.Text)<>'' then
       s := s + ' and VENDNAME like ''%'+edNazwa.Text+'%'' ';
  end else
  if  trim(edNazwa.Text)<>'' then
     s := 'VENDNAME like ''%'+edNazwa.Text+'%'' ';
  if s<>'' then begin
    qDostawcy.Filter := s;
    qDostawcy.Filtered := True;
  end;
end;

procedure TFListaDostawcow.FormShow(Sender: TObject);
begin
  Dostawca := '';
  qDostawcy.Open;
end;

end.
